package com.studyweb.service.impl;

import com.studyweb.mapper.NoteMapper;
import com.studyweb.pojo.entity.Note;
import com.studyweb.service.NoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class NoteServiceImpl implements NoteService {
    
    @Autowired
    private NoteMapper noteMapper;
    
    @Override
    public boolean addNote(Note note) {
        return noteMapper.insert(note) > 0;
    }
    
    @Override
    public boolean deleteNote(Long id) {
        return noteMapper.deleteById(id) > 0;
    }
    
    @Override
    public boolean deleteNotes(List<Long> ids) {
        return noteMapper.deleteBatch(ids) > 0;
    }
    
    @Override
    public boolean updateNote(Note note) {
        return noteMapper.update(note) > 0;
    }
    
    @Override
    public Note getNoteById(Long id) {
        return noteMapper.selectById(id);
    }
    
    @Override
    public List<Note> getAllNotes() {
        return noteMapper.selectAll();
    }
    
    @Override
    public List<Note> getNotesByNoteType(String title) {
        // 处理空字符串情况，将其转换为null
        if (title != null && title.isEmpty()) {
            title = null;
        }
        return noteMapper.selectByNoteType(title);
    }
}